(function () {
	var $ax = function (url,success,error,exOptions) {
		var options = {};
        options["type"]="post";
        options["data"]={};
        options["dataType"]="json";
        options["async"]=false;
        options["url"]=url;
        options["success"]=success;
        options["error"]=error;
        if(exOptions) {
            for (var i in exOptions) {
                options[i] = exOptions[i];
            }
        }
		this.axOptions = options;
	};
	
	$ax.prototype = {
		start : function () {	
			var me = this;
			
			if (this.axOptions.url.indexOf("?") == -1) {
				this.axOptions.url = this.axOptions.url + "?jstime=" + new Date().getTime();
			} else {
				this.axOptions.url = this.axOptions.url + "&jstime=" + new Date().getTime();
			}

			var ajaxOptions = {};
			for(var i in this.axOptions){
                ajaxOptions[i] =this.axOptions[i];
			}
            ajaxOptions["beforeSend"] = function(data) {
            };
            ajaxOptions["success"] = function(data) {
                me.axOptions.success(data);
            };
            ajaxOptions["error"] = function(data) {
                me.axOptions.error(data);
            };
			$.ajax(ajaxOptions);
		}, 
		
		set : function (key, value) {
			if (typeof key == "object") {
				for (var i in key) {
					if (typeof i == "function")
						continue;
					this.axOptions.data[i] = key[i];
				}
			} else {
				this.axOptions.data[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
			}
			return this;
		},
		
		setData : function(data){
            this.axOptions.data = data;
            return this;
		},
		
		setJsonStringifyData :function (data) {
            this.axOptions.data = JSON.stringify(data);
            return this;
        },

		clear : function () {
			this.axOptions.data = {};
			return this;
		}
	};
	
	window.$ax = $ax;
	
} ());